package ocr;

/**
 * @author 啊林
 * @date 2022/4/8
 * @time 20:58
 */

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

// 通用文字识别-标准版 示例代码
public class RequestDemo {
    public static void main(String[] args) {
        String path = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);


        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");



        // 设置jsonBody参数
        String jsonBody = "url=https:/baidu-ai.bj.bcebos.com/ocr/ocr.jpg&detect_direction=false&paragraph=false&probability=false";
        request.setJsonBody(jsonBody);

        ApiExplorerClient client = new ApiExplorerClient();

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}